<?php

// +----------------------------------------------------------------------
// | Apprh.Shop
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2027 http://www.apprh.com All rights reserved.
// +----------------------------------------------------------------------
// | Notice: This code is not open source, it is strictly prohibited
// |         to distribute the copy, otherwise it will pursue its
// |         legal responsibility.
// +----------------------------------------------------------------------
// | Author: 
// +----------------------------------------------------------------------

namespace app\admin\controller;

use service\DataService;
use service\LogService;
use controller\BasicAdmin;
use think\Db;

/**
 * 疾病管理
 * Class Disease
 * @package app\admin\controller
 * @author  
 * @date 2019/07/25
 */
class Disease extends BasicAdmin
{
    /**
     * 指定当前数据表
     * @var string
     */
    public $table = 'Disease';

    /**
     * Disease 列表
     * @return mixed
     */
    public function index()
    {
        $title = $this->request->param('title');
        $this->assign('title', $title);
        $this->title = '疾病管理';
        $get = $this->request->get();
        $map = ['is_deleted' => 0];
        if(isset($title)){
            $map['title'] = ['like', "%".$title."%"];
        }
        $db = Db::name($this->table)->where($map);

        // 应用搜索条件
        foreach (['title'] as $key) {
            if (isset($get[$key]) && $get[$key] !== '') {
                $db->where($key, 'like', "%{$get[$key]}%");
            }
        }
        $db->order('sort asc');
        $data = parent::_list($db, true, false);
        return $this->fetch('', $data);
    }

    /**
     * 添加
     */
    public function add() {
        return $this->_form($this->table, 'form');
    }

    /**
     * 编辑
     */
    public function edit() {
        return $this->add();
    }

    /**
     * 删除
     */
    public function del() {
        if (DataService::update($this->table)) {
            LogService::write('系统设置', '疾病删除成功');
            $this->success("删除成功！", '');
        }
        $this->error("删除失败，请稍候再试！");
    }

    /**
     * 禁用
     */
    public function forbid() {
        if (DataService::update($this->table)) {
            LogService::write('系统设置', '疾病禁用成功');
            $this->success("禁用成功！", '');
        }
        $this->error("禁用失败，请稍候再试！");
    }

    /**
     * 启用
     */
    public function resume() {
        if (DataService::update($this->table)) {
            LogService::write('系统设置', '疾病启用成功');
            $this->success("启用成功！", '');
        }
        $this->error("启用失败，请稍候再试！");
    }

    /**
     * 位置 表单数据前缀方法
     * @param array $vo
     */
    protected function _form_filter(&$vo) {
        if ($this->request->isGet()) {
            
        }
    }

}
